﻿/*
   Open Intel 
   Copyright © 2011 – ISC. All Rights Reserved.
*/


using System;
using Caliburn.Micro;
using OI.Framework;

namespace OI.Async
{
    public class SharingServiceRead : SharingServiceBase
    {
        public Guid ID { get; private set; }

        public SharingServiceRead(Guid id)
        {
            ID = id;
            Client.ReadStateCompleted += ReadStateCompleted;
        }

        public void ReadStateCompleted(object sender, SharingService.ReadStateCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                IoC.Get<IShell>().HandleException(e.Error, "Error reading share state");
            }

            Results = e.Result;
            Completed(this, new ResultCompletionEventArgs { Error = e.Error });
        }


        public override void Execute(ActionExecutionContext context)
        {
            Client.ReadStateAsync(ID);
        }

        public override event EventHandler<ResultCompletionEventArgs> Completed;
    }
}
